package com.gec.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysChargeDetail;
import com.gec.model.entity.SysChargeItems;
import com.gec.model.vo.SysChargeDetailQueryVo;
import com.gec.model.vo.SysChargeItemsQueryVo;
import com.gec.system.service.SysChargeDetailService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 收费明细表 前端控制器
 * </p>
 *
 * @author lys
 * @since 2023-12-08
 */
@Api(tags = "收费明细管理控制器")
@RestController
@RequestMapping("/admin/system/sysChargeDetail/")
public class SysChargeDetailController {

    @Autowired
    private SysChargeDetailService sysChargeDetailService;

    @ApiOperation("分页查询收费项目列表")
    @GetMapping("{page}/{limit}")
    public Result findPage(@PathVariable Long page,
                           @PathVariable Long limit,
                           SysChargeDetailQueryVo vo){

        IPage<SysChargeDetail> page1 = new Page<>(page,limit);
        page1 = this.sysChargeDetailService.selectPage(page1,vo);
        return Result.ok(page1);
    }

    @ApiOperation("添加收费明细")
    @PostMapping("addDetail")
    public Result addDetail(@RequestBody SysChargeDetail sysChargeDetail){

        boolean save = this.sysChargeDetailService.save(sysChargeDetail);
        if (save){
            return Result.ok();
        }

        return Result.fail();
    }



    @ApiOperation("根据id查询收费明细")
    @GetMapping("getDetailById/{id}")
    public Result getDetailById(@PathVariable Long id){
        QueryWrapper<SysChargeDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        SysChargeDetail one = this.sysChargeDetailService.getOne(wrapper);
        return Result.ok(one);
    }

    @ApiOperation("根据业主id和收费类型查询收费明细")
    @GetMapping("getDetails")
    public Result getDetailByIdAndType(SysChargeDetailQueryVo vo){

        List<SysChargeDetail>detailList = this.sysChargeDetailService.getDetailByIdAndType(vo);
        return Result.ok(detailList);
    }


    @ApiOperation("根据id修改收费明细")
    @PostMapping("updateDetailById")
    public Result updateDetailById(@RequestBody SysChargeDetail sysChargeDetail){


        boolean b = this.sysChargeDetailService.updateById(sysChargeDetail);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }


    @ApiOperation("根据id删除收费明细")
    @DeleteMapping("removeDetailById/{id}")
    public Result removeDetailById(@PathVariable Long id){

        boolean b = this.sysChargeDetailService.removeById(id);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

    @ApiOperation("根据ids批量删除收费明细")
    @DeleteMapping("removeDetailByIds")
    public Result removeDetailByIds(@RequestBody List<Long> ids){

        boolean b = this.sysChargeDetailService.removeByIds(ids);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

}

